<script setup lang="ts">
import {onMounted, ref} from "vue";
import {useRouter} from "vue-router";
import myAxios from "../plugins/myAxios.ts";
import {showFailToast, showSuccessToast} from "vant";
import {getCurrentUser} from "../services/user.ts";

// const user = ref({
//   id: 1,
//   username: 'name',
//   userAccount: 'account',
//   avatarUrl: 'https://tupian.qqw21.com/article/UploadPic/2020-9/20209112265667154.jpg',
//   gender: '男',
//   phone: '1232313',
//   email: '4232@qq.com',
//   userCode: '213',
//   createTime: new Date(),
// });

const user = ref()

const router = useRouter();

const userEdit = (editKey: string, editName: string, currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      editName,
      currentValue
    }
  })
}

onMounted(async ()=> {
  const res = await getCurrentUser();
  if (res) {
    user.value = res;
    showSuccessToast('获取用户信息成功')
  } else {
    showFailToast('获取用户信息失败');
  }
})
</script>

<template>
    <template v-if="user">
      <van-cell title="昵称" is-link :value="user.username" @click="userEdit('username', '昵称', user.username)"/>
      <van-cell title="账号" :value="user.userAccount"/>
      <van-cell title="头像" is-link @click="userEdit('avatarUrl', '头像', user.avatarUrl)">
        <img style="height: 47px" :src="user.avatarUrl">
      </van-cell>
      <van-cell title="性别" is-link @click="userEdit('gender', '性别', user.gender)" :value="user.gender"  />
      <van-cell title="电话" is-link @click="userEdit('phone', '电话', user.phone)" :value="user.phone"/>
      <van-cell title="邮箱" is-link @click="userEdit('email', '邮箱', user.email)" :value="user.email"/>
      <van-cell title="用户编号" :value="user.planetCode"/>
      <van-cell title="注册时间" :value="user.createTime"/>
    </template>
</template>

<style scoped>

</style>